define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/vacationlog/index',
                    add_url: 'aps/vacationlog/add',
                    edit_url: 'aps/vacationlog/edit',
                    del_url: 'aps/vacationlog/del',
                    multi_url: 'aps/vacationlog/multi',
                    table: 'aps_vacationlog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'man.name', title: __('Man.name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', formatter: Controller.api.formatter.man},
                        {field: 'startdate', title: __('Startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'enddate', title: __('Enddate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'type', title: __('Type'), searchList: {"婚假":__('婚假'),"喪假":__('喪假'),"傷病假":__('傷病假'),"事假":__('事假'),"公假":__('公假'),"公傷病假":__('公傷病假'),"特別休假":__('特別休假'),"其他":__('其他')}, formatter: Table.api.formatter.normal},
                        {field: 'mark', title: __('Mark')},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'man.id', title: __('Man.id')},
                        //{field: 'man.name', title: __('Man.name')},
                        //{field: 'man.number', title: __('Man.number')},
                        //{field: 'man.state', title: __('Man.state')},
                        //{field: 'man.devicetype1_id', title: __('Man.devicetype1_id')},
                        //{field: 'man.devicetype2_id', title: __('Man.devicetype2_id')},
                        //{field: 'man.devicetype3_id', title: __('Man.devicetype3_id')},
                        //{field: 'man.devicetype4_id', title: __('Man.devicetype4_id')},
                        //{field: 'man.devicetype5_id', title: __('Man.devicetype5_id')},
                        //{field: 'man.devicetype6_id', title: __('Man.devicetype6_id')},
                        //{field: 'man.devicetype7_id', title: __('Man.devicetype7_id')},
                        //{field: 'man.devicetype8_id', title: __('Man.devicetype8_id')},
                        //{field: 'man.devicetype9_id', title: __('Man.devicetype9_id')},
                        //{field: 'man.devicetype10_id', title: __('Man.devicetype10_id')},
                        //{field: 'man.devicetype11_id', title: __('Man.devicetype11_id')},
                        //{field: 'man.devicetype12_id', title: __('Man.devicetype12_id')},
                        //{field: 'man.devicetype13_id', title: __('Man.devicetype13_id')},
                        //{field: 'man.devicetype14_id', title: __('Man.devicetype14_id')},
                        //{field: 'man.devicetype15_id', title: __('Man.devicetype15_id')},
                        //{field: 'man.devicetype16_id', title: __('Man.devicetype16_id')},
                        //{field: 'man.devicetype17_id', title: __('Man.devicetype17_id')},
                        //{field: 'man.devicetype18_id', title: __('Man.devicetype18_id')},
                        //{field: 'man.devicetype19_id', title: __('Man.devicetype19_id')},
                        //{field: 'man.devicetype20_id', title: __('Man.devicetype20_id')},
                        //{field: 'man.devicetype21_id', title: __('Man.devicetype21_id')},
                        //{field: 'man.devicetype22_id', title: __('Man.devicetype22_id')},
                        //{field: 'man.devicetype23_id', title: __('Man.devicetype23_id')},
                        //{field: 'man.devicetype24_id', title: __('Man.devicetype24_id')},
                        //{field: 'man.devicetype25_id', title: __('Man.devicetype25_id')},
                        //{field: 'man.devicetype26_id', title: __('Man.devicetype26_id')},
                        //{field: 'man.devicetype27_id', title: __('Man.devicetype27_id')},
                        //{field: 'man.devicetype28_id', title: __('Man.devicetype28_id')},
                        //{field: 'man.devicetype29_id', title: __('Man.devicetype29_id')},
                        //{field: 'man.devicetype30_id', title: __('Man.devicetype30_id')},
                        //{field: 'man.create_time', title: __('Man.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'man.update_time', title: __('Man.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                man: function (value, row, index) {
                    if (row.man_id == 0) {
                        return "全員";
                    }
                    return value;
                },
            }
        }
    };
    return Controller;
});